package com.chzc.fm.duotin.adapter.recyclerview;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.chzc.fm.duotin.R;
import com.chzc.fm.duotin.bean.home.RecommendDataList;
import com.chzc.fm.duotin.ui.home.utils.JumpManager;
import com.chzc.fm.duotin.utils.ImageUtil;
import com.nostra13.universalimageloader.core.ImageLoader;

import java.util.List;

/**
 * Created by Administrator on 2016/6/25.
 */
public class HomeAdapter extends RecyclerView.Adapter<HomeAdapter.ViewHodler>{
    LayoutInflater inflater;
    private Context context;
    private  List<RecommendDataList>list;
    public HomeAdapter(Context context, List<RecommendDataList>list)
    {
        super();
        this.list = list;
        this.context = context;
        inflater = LayoutInflater.from(context);
    }

    @Override
    public ViewHodler onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = inflater.inflate(R.layout.fragment_home_rv_item,null);

        return new ViewHodler(view);
    }

    @Override
    public void onBindViewHolder(ViewHodler holder, final int position) {
        RecommendDataList data = list.get(position);
        //设置图片
        ImageLoader.getInstance().displayImage(data.getImage_url(),holder.imageView, ImageUtil.getRoundOptions());
        //设置文字内容
        holder.tvTitles.setText(data.getTitle());
        holder.tvContents.setText(data.getSub_title());
        //设置监听事JumpManager.jumpTopicListView(getContext());
        holder.imageView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                JumpManager.jumpTopicListView2(context,list.get(position).getItem_value());
            }
        });



    }

    @Override
    public int getItemCount() {
        return list==null?0:list.size();
    }

    public class ViewHodler extends RecyclerView.ViewHolder{

        private ImageView imageView;
        private TextView tvTitles,tvContents;

        public ViewHodler(View itemView) {
            super(itemView);
            imageView = (ImageView) itemView.findViewById(R.id.ivConentLeft);
            tvTitles = (TextView) itemView.findViewById(R.id.tvTitles);
            tvContents = (TextView) itemView.findViewById(R.id.tvContents);

        }
    }
}
